//
//  NNController.h
//  symbrion
//
//  Created by Berend Weel on 3/22/13.
//  Copyright (c) 2013 Berend Weel. All rights reserved.
//

#ifndef symbrion_NNController_h
#define symbrion_NNController_h

#include <vector>

#include "Fixed32.h"
#include "MultiLayeredPerceptron.h"

#include "EAController.h"
#include "ShapeOrganism.h"

#define INPUTLAYERSIZE 10
#define HIDDENLAYERSIZE 10
#define OUTPUTLAYERSIZE 10

class NNController : public EAController {
public:
    NNController(WorldModel *worldModel, RobotType *robot);
    virtual ~NNController();
    
    virtual void step();
    
    virtual void setGenome(std::vector<LIOReal> _genome);
    virtual Individual *randomIndividual();
    
    void loadFromFile(std::string file);
    
private:
    void loadWeights();
    void transmitGenome();
    void setHinge();
    void createShape();
    void setLEDs(int colour);
    void createNetwork();
    
    void receiveMessages();
    void sendMessages();
    
    Shape::Organism *organism;
    Shape::Sequence *sequence;
    
    std::vector<LIOReal> weights;
    std::vector<LIOReal> inputHingePositions;
    std::vector<LIOReal> outputHingePositions;
    
    MultiLayeredPerceptron *network;
    
    LIOReal nextHingePosition;
    LIOReal prevHingePosition;
};

#endif
